package com.jcodecraeer.xrecyclerview.progressindicator.indicator;

import ohos.agp.animation.Animator;
import ohos.agp.animation.AnimatorValue;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;

import java.util.ArrayList;
import java.util.List;

public class BallTrianglePathIndicator extends BaseIndicatorController {
    private float scaleFloat =0.5f;
    float[] translateX=new float[3],translateY=new float[3];

    @Override
    public void draw(Canvas canvas, Paint paint) {
        float radius=getWidth()/10;
        float x = getWidth()/ 2;
        float y=getHeight()/2;

        canvas.save();
        canvas.translate(x - radius * 2 - radius, y+y/2);
        canvas.drawCircle(0, 0, radius, paint);
        canvas.restore();

        canvas.save();
        canvas.translate(x, y/2);
        canvas.drawCircle(0, 0, radius, paint);
        canvas.restore();

        canvas.save();
        canvas.translate(x + radius * 2 + radius, y+y/2);
        canvas.drawCircle(0,0,radius, paint);
        canvas.restore();
    }

    @Override
    public List<Animator> createAnimation() {
        List<Animator> animators=new ArrayList<>();

        AnimatorValue scaleAnim = new AnimatorValue();
        scaleAnim.setLoopedCount(-1);
        scaleAnim.setDuration(1500);
        scaleAnim.setValueUpdateListener(new AnimatorValue.ValueUpdateListener() {
            @Override
            public void onUpdate(AnimatorValue animatorValue, float v) {
//                scaleFloat = v;
                getTarget().setRotation(v*180);
            }
        });
        scaleAnim.start();
        animators.add(scaleAnim);
        return animators;
    }
}
